package com.cw.jeeyt.service.converter.api;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.common.enums.EnumDataJavaType;
import com.cw.jeeyt.common.enums.EnumYn;
import com.cw.jeeyt.service.bo.api.ApiFacadeObjParamBo;
import com.cw.jeeyt.dao.model.api.ApiFacadeObjParamDo;
import com.cw.lang.common.utils.CollectionUtil;
import com.cw.lang.common.utils.StringUtil;

/**
 * 接口方法参数对象具体参数转换类
 *
 * @author chenw
 * @date 2019-03-10 13:05:36
 */
public class ApiFacadeObjParamConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static ApiFacadeObjParamBo do2Bo(ApiFacadeObjParamDo model) {
        if (model == null) {
            return null;
        }
        String paramJavaTypeCn = StringUtil.isNotBlank(model.getParamJavaType()) ? EnumDataJavaType.find(
            model.getParamJavaType())
            .getDescription() : "";
        String isRequiredCn = StringUtil.isNotBlank(model.getIsRequired()) ? EnumYn.find(model.getIsRequired())
            .getDescription() : "";
        ApiFacadeObjParamBo bo = new ApiFacadeObjParamBo();
        bo.setId(model.getId());
        bo.setObjId(model.getObjId());
        bo.setParamCode(model.getParamCode());
        bo.setParamJavaType(model.getParamJavaType());
        bo.setParamJavaTypeCn(paramJavaTypeCn);
        bo.setEnumId(model.getEnumId());
        bo.setPojoId(model.getPojoId());
        bo.setIsRequired(model.getIsRequired());
        bo.setIsRequiredCn(isRequiredCn);
        bo.setIsList(model.getIsList());
        bo.setMaxLength(model.getMaxLength());
        bo.setParamDesc(model.getParamDesc());
        bo.setParamDemo(model.getParamDemo());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static ApiFacadeObjParamDo bo2Do(ApiFacadeObjParamBo bo) {
        if (bo == null) {
            return null;
        }
        ApiFacadeObjParamDo model = new ApiFacadeObjParamDo();
        model.setId(bo.getId());
        model.setObjId(bo.getObjId());
        model.setParamCode(bo.getParamCode());
        model.setParamJavaType(bo.getParamJavaType());
        model.setEnumId(bo.getEnumId());
        model.setPojoId(bo.getPojoId());
        model.setIsRequired(bo.getIsRequired());
        model.setIsList(bo.getIsList());
        model.setMaxLength(bo.getMaxLength());
        model.setParamDesc(bo.getParamDesc());
        model.setParamDemo(bo.getParamDemo());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<ApiFacadeObjParamBo> doList2BoList(List<ApiFacadeObjParamDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), ApiFacadeObjParamConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<ApiFacadeObjParamDo> boList2DoList(List<ApiFacadeObjParamBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), ApiFacadeObjParamConverter::bo2Do));
    }
}
